I need to make a dropdown menu that shows information depending on what the user chooses in the first one. I am using PHP and MySql.
I am new!
I looked for tutorials and I am trying to understand the code... however it is not clear enough. I will say what I understand so you can tell me where I am wrong.
Expand|Select|Wrap|Line Numbers
- <?PHP
- require_once('connection.php');
- require_once('open_db.php');
- $query1=mysql_query("SELECT Route_From as Desde FROM route") or die(mysql_error());
- $query2=mysql_query("SELECT * FROM route WHERE Route_From=".$_POST["Desde"].""") or die(mysql_error());
- ?>
- <form name="check" method="post">
- <!-- First Drop Down starts here -->
- <select name="select1" onchange="this.form.submit()">
- <?PHP
- while ($row = mysql_fetch_assoc($query1))
- {
- echo ("<option>{$row['Route_From']}</option>");
- }
- ?>
- </select>
- <?PHP
- if (isset($_POST["select1"]))
- ?>
- <select name="select2">
- <?PHP
- while($row = mysql_fetch_assoc($query2))
- {
- echo("<option>{$row['Route_To']}</option>");
- }
- ?>
- </select>
- </form>
- I connect to MySql (that works fine)
- I create the queries
- I create the first menu and start filling it up and with the "onchange", when a user selects an option, what he chose is submitted.
- When the first option is submitted, this info is captured with:
<?PHP
if (isset($_POST["select1"]))
?>
- The the second query is done and the second menu is filled.
When I execute the page the error that is shown is the following:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 1
I hope someone can help me!
Bye